﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MeetIterator
{
    public class Waitress
    {
        PancakeHouseMenu pancakeHouseMenu;
        DinnerMenu dinerMenu;

        public Waitress(PancakeHouseMenu pancakeHouseMenu, DinnerMenu dinerMenu)
        {
            this.pancakeHouseMenu = pancakeHouseMenu;
            this.dinerMenu = dinerMenu;
        }

        public void PrintMenu()
        {
            Iterator pancakeIterator = pancakeHouseMenu.createIterator();
            Iterator dinerIterator = dinerMenu.createIterator();
            Console.WriteLine("Menu\n------------\n BreakFast");
            printMenu(pancakeIterator);
            Console.WriteLine("\nLanch");
            printMenu(dinerIterator);
        }


        /// <summary>
        /// 使用迭代方式使两种情况下打印菜单的方式相同
        /// 但是在C#中，两种情况都可以使用foreach而被统一实现
        /// 可参考IEnumerable【yield return】
        /// </summary>
        /// <param name="iterator"></param>
        private void printMenu(Iterator iterator)
        {
            while(iterator.hasNext())
            {
                MenuItem menuItem = (MenuItem)iterator.next();
                Console.WriteLine(menuItem.GetName() + ", ");
                Console.WriteLine(menuItem.GetPrice() + " -- ");
                Console.WriteLine(menuItem.GetDescription());
            }
        }
    }
}
